package com.dunshan.cart.controller;


import com.alibaba.fastjson.JSON;
import com.dunshan.cart.feing.OderServiceFeignClient;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author dunshan
 * @program: dunshan-pef
 * @description: 购物车服务index
 * @date 2021-10-02 14:47:29
 */
@Log4j2
@RestController
public class CartController {

    @Resource
    OderServiceFeignClient oderServiceFeignClient;

    @Autowired
    HttpServletRequest request;

    @GetMapping("/cart/user/{id}")
    public String cartProduct(@PathVariable(value = "id") Integer id) {
        String result = null;
        String dunshan = request.getHeader("dunshan");
        log.info("/cart/user/" + dunshan);
        if ("7DGroup".equals(dunshan)) {
            result = oderServiceFeignClient.openOrdertInfo(id);
            return result = "-> dunshan-cart" + result + "<<header>>" + dunshan;
        }
        result = oderServiceFeignClient.openOrdertInfo(id);
        result = "-> dunshan-cart" + result + "<<header>>" + "抱歉没有头信息";
        return result;
    }


    /**
     * 查询用户信息
     *
     * @return
     */
    @GetMapping("/cart/admin")
    public Object selectInfo() {
        return JSON.toJSON(oderServiceFeignClient.selectUserInfo());
    }
}
